package com.neuedu.servlet;

import com.neuedu.entity.Admin;
import com.neuedu.service.AdminService;
import com.neuedu.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//@WebServlet(name = "LoginServlet",urlPatterns = {"/login"})
@WebServlet({"/login"})
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String adminName=request.getParameter("adminName");//一定要于jsp文件里的name一致
        String password=request.getParameter("password");
       //获取用户的登录名以及密码用于service层的业务
        AdminService adminService=new AdminServiceImpl();
        Admin admin=adminService.login(adminName,password);
        if (null!=admin){
            response.sendRedirect("/success.jsp");
        }
        else {
            response.sendRedirect("/fail.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         System.out.print("接收到请求");
    }
}
